package com.java110.mall.cart.dao.impl;

import com.alibaba.fastjson.JSONObject;
import com.java110.utils.constant.ResponseConstant;
import com.java110.utils.exception.DAOException;
import com.java110.core.base.dao.BaseServiceDao;
import com.java110.mall.cart.dao.IHousekeepingServPoolServiceDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 家政维修池服务 与数据库交互
 * Created by wuxw on 2017/4/5.
 */
@Service("housekeepingServPoolServiceDaoImpl")
//@Transactional
public class HousekeepingServPoolServiceDaoImpl extends BaseServiceDao implements IHousekeepingServPoolServiceDao {

    private static Logger logger = LoggerFactory.getLogger(HousekeepingServPoolServiceDaoImpl.class);





    /**
     * 保存家政维修池信息 到 instance
     * @param info   bId 信息
     * @throws DAOException DAO异常
     */
    @Override
    public void saveHousekeepingServPoolInfo(Map info) throws DAOException {
        logger.debug("保存家政维修池信息Instance 入参 info : {}",info);

        int saveFlag = sqlSessionTemplate.insert("housekeepingServPoolServiceDaoImpl.saveHousekeepingServPoolInfo",info);

        if(saveFlag < 1){
            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"保存家政维修池信息Instance数据失败："+ JSONObject.toJSONString(info));
        }
    }


    /**
     * 查询家政维修池信息（instance）
     * @param info bId 信息
     * @return List<Map>
     * @throws DAOException DAO异常
     */
    @Override
    public List<Map> getHousekeepingServPoolInfo(Map info) throws DAOException {
        logger.debug("查询家政维修池信息 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.getHousekeepingServPoolInfo",info);

        return businessHousekeepingServPoolInfos;
    }


    /**
     * 修改家政维修池信息
     * @param info 修改信息
     * @throws DAOException DAO异常
     */
    @Override
    public void updateHousekeepingServPoolInfo(Map info) throws DAOException {
        logger.debug("修改家政维修池信息Instance 入参 info : {}",info);

        int saveFlag = sqlSessionTemplate.update("housekeepingServPoolServiceDaoImpl.updateHousekeepingServPoolInfo",info);

        if(saveFlag < 1){
            throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR,"修改家政维修池信息Instance数据失败："+ JSONObject.toJSONString(info));
        }
    }

     /**
     * 查询家政维修池数量
     * @param info 家政维修池信息
     * @return 家政维修池数量
     */
    @Override
    public int queryHousekeepingServPoolsCount(Map info) {
        logger.debug("查询家政维修池数据 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.queryHousekeepingServPoolsCount", info);
        if (businessHousekeepingServPoolInfos.size() < 1) {
            return 0;
        }

        return Integer.parseInt(businessHousekeepingServPoolInfos.get(0).get("count").toString());
    }

    @Override
    public int queryStaffServCount(Map info) {
        logger.debug("查询家政维修池数据 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.queryStaffServCount", info);
        if (businessHousekeepingServPoolInfos.size() < 1) {
            return 0;
        }

        return Integer.parseInt(businessHousekeepingServPoolInfos.get(0).get("count").toString());
    }

    @Override
    public List<Map> queryStaffServs(Map info) {
        logger.debug("查询家政维修池信息 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.queryStaffServs",info);

        return businessHousekeepingServPoolInfos;
    }
    @Override
    public int queryStaffFinishServCount(Map info) {
        logger.debug("查询家政维修池数据 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.queryStaffFinishServCount", info);
        if (businessHousekeepingServPoolInfos.size() < 1) {
            return 0;
        }

        return Integer.parseInt(businessHousekeepingServPoolInfos.get(0).get("count").toString());
    }

    @Override
    public List<Map> queryStaffFinishServs(Map info) {
        logger.debug("查询家政维修池信息 入参 info : {}",info);

        List<Map> businessHousekeepingServPoolInfos = sqlSessionTemplate.selectList("housekeepingServPoolServiceDaoImpl.queryStaffFinishServs",info);

        return businessHousekeepingServPoolInfos;
    }


}
